﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AppSocketModel;
using AppSocketService.Device;
using BCGPSCommon;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BCGPSRESTful.Controllers.Page.Device
{
    /// <summary>
    /// 设备信息  -- 系统功能
    /// </summary>
    [ApiExplorerSettings(GroupName = "SystemAccount")]
    [Route("api/[controller]")]
    [ApiController]
    public class DeviceController : PageBaseController
    {
        private IDeviceService deviceService;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="deviceService"></param>
        public DeviceController(IDeviceService deviceService)
        {
            this.deviceService = deviceService;
        }


        /// <summary>
        /// 查询全部设备信息 -- 分页
        /// </summary> 
        /// <param name="imei"></param>  
        /// <param name="desc">是否倒序</param>
        /// <param name="index">页码</param>
        /// <param name="size">记录数</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<DeviceDto>), 200)]
        public PageableList<DeviceDto> QueryListPage(string imei,bool? desc = true, int? index = 0, int? size = 20)
        {

            return deviceService.GetList(imei,desc.Value, index.Value, size.Value);
        }
        /// <summary>
        /// 查询设备信息
        /// </summary>
        /// <param name="imei"></param>  
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(DeviceDto), 200)]
        public DeviceDto Query(string imei)
        {
            return deviceService.Get(imei);
        }

        /// <summary>
        /// 初始化统计结果,重新统计
        /// </summary>
        /// <param name="imei"></param>  
        /// <returns></returns>
        [HttpPut("[action]")]
        [ProducesResponseType(typeof(DeviceDto), 200)]
        public DeviceDto ResetCount(string imei)
        {
            return deviceService.ResetCount(imei);
        }
    }
}